import java.util.Deque;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;

public class num914 {
    public boolean hasGroupsSizeX(int[] deck) {
        if(deck.length < 2) {
            return false;
        }
        HashMap<Integer,Integer> map = new HashMap<>();
        for (int i = 0; i < deck.length; i++) {
            if(!map.containsKey(deck[i])) {
                map.put(deck[i],1);
            }else {
                map.put(deck[i],map.get(deck[i]) + 1);
            }
        }
        Deque<Integer> queue = new LinkedList<>();
        for(Map.Entry<Integer,Integer> entry : map.entrySet()) {
            queue.offer(entry.getValue());
        }
        int x = 0;
        while (!queue.isEmpty()) {
            if(x == 0) {
                x = queue.poll();
            }else {
                x = gcd(x,queue.poll());
                if(x == 1) {
                    return false;
                }
            }
        }
        return true;
    }

    private int gcd(int p, Integer q) {
        if(p % q == 0) {
            return q;
        }
        return gcd(q,p%q);
    }
}
